import Mock from "mockjs";

Mock.mock("/home/getdata", "get", () => {
  return Mock.mock({
    code: 200,
    msg: "success",
    data: {
      name: "admin",
      age: 30,
      city: "北京",
      role: "超级管理员",
    },
  });
});

// 登录接口
Mock.mock("/login", "post", (options) => {
  const { username, password } = JSON.parse(options.body);
  
  // 简单验证逻辑
  if (username === "admin" && password === "123456") {
    return Mock.mock({
      code: 200,
      msg: "登录成功",
      data: {
        token: "@guid",
        userInfo: {
          id: "@increment",
          username: username,
          name: "管理员",
          avatar: "@image('100x100', '#4A7BF7', 'admin')",
        }
      }
    });
  } else {
    return Mock.mock({
      code: 401,
      msg: "用户名或密码错误",
      data: null
    });
  }
});

// 获取用户信息接口（包含权限和角色）
Mock.mock("/api/user/info", "get", () => {
  return Mock.mock({
    code: 200,
    msg: "success",
    data: {
      id: "@increment",
      username: "admin",
      name: "管理员",
      avatar: "@image('100x100', '#4A7BF7', 'admin')",
      roles: ["admin"],
      permissions: [
        "system:user:view",
        "system:user:add",
        "system:user:edit",
        "system:user:delete",
        "system:role:view",
        "system:role:add",
        "system:role:edit",
        "system:role:delete"
      ]
    }
  });
});

// 获取路由信息接口
Mock.mock("/user/routes", "get", () => {
  return Mock.mock({
    code: 200,
    msg: "success",
    data: [
      {
        id: 1,
        name: "Dashboard",
        path: "/dashboard",
        component: "Dashboard",
        meta: {
          title: "仪表板",
          icon: "dashboard",
          permissions: ["dashboard:view"]
        }
      },
      {
        id: 2,
        name: "System",
        path: "/system",
        meta: {
          title: "系统管理",
          icon: "setting",
          permissions: ["system:view"]
        },
        children: [
          {
            id: 3,
            name: "User",
            path: "/system/user",
            component: "User",
            meta: {
              title: "用户管理",
              permissions: ["system:user:view"]
            }
          },
          {
            id: 4,
            name: "Role",
            path: "/system/role",
            component: "Role",
            meta: {
              title: "角色管理",
              permissions: ["system:role:view"]
            }
          }
        ]
      }
    ]
  });
});